<template>
  <el-dialog :visible.sync="dialogVisible" :title="'进项发票处理'" :close-on-click-modal="false" width="1200px" v-drag2anywhere>
    <div>
      <el-form :model="formData" ref="formData" label-width="100px">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="订单号:">
              {{formData.ordercode}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="订单渠道:">
              {{formData.platform}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="订单总额:">
              {{formData.amount}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开票总额:">
              {{formData.supamount}} ({{100-formData.suprate}}%)
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="开票明细:">
              <el-table :data="formData.goods" border>
                <el-table-column type="index" label="序号" width="60px" align="center"></el-table-column>
                <el-table-column prop="title" label="商品名称"></el-table-column>
                <el-table-column prop="model" label="规格型号" width="100px"></el-table-column>
                <el-table-column prop="unit" label="单位" width="100px" align="center"></el-table-column>
                <el-table-column prop="count" label="数量" width="100px" align="center"></el-table-column>
                <el-table-column prop="supprice" label="单价" width="100px" align="center">
                  <template v-slot="scope">
                    {{scope.row.supprice|number(2)}}
                  </template>
                </el-table-column>
                <el-table-column prop="suptotal" label="小计" width="100px" align="center">
                  <template v-slot="scope">
                    {{scope.row.suptotal|number(2)}}
                  </template>
                </el-table-column>
              </el-table>
              <div style="text-align: right;padding: 2px 0px;border:1px solid #E3E3E3; border-top: none;">
                <span style="margin-right:15px">应开总额:{{formData.supamount|number(2)}}</span>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="发票号码:" size="medium">
              <el-tag :key="tag" v-for="tag in supticket_ids">
                {{tag}}
              </el-tag>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="进销项:">
              <el-radio-group v-model="supticket_same">
                <el-radio label="相符"  ></el-radio>
                <el-radio label="不相符" ></el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
            <el-form-item label="发票附件:">
              <viewer :images="formData.supticket_attach">
                <img v-for="src in formData.supticket_attach" :src="src.url" :key="src.name" fit="fill"
                  style="width: 80px; height: 80px; padding:1px; background-color: #e5e5e5; margin: 2px;">
              </viewer>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际开票额:">
               <el-input-number v-model="formData.supticket_amount" style="width: 180px;" ></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>



        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="状态:">
              <el-select v-model="formData.supticket_status" style="width: 100%;">
                <el-option label="待开具上传" value="0"></el-option>
                <el-option label="已上传,待审核" value="1"></el-option>
                <el-option label="审核通过，待邮寄" value="2"></el-option>
                <el-option label="审核不通过" value="3"></el-option>
                <el-option label="已签收" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item label="审核意见:">
              <el-input :disabled="formData.supticket_status!=3" v-model="formData.supticket_verifymsg" placeholder="请在此填写审核不通过原因"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="签收日期">
              <el-date-picker  type="date" value-format="yyyy-MM-dd" :disabled="formData.supticket_status!=4" v-model="formData.supticket_signedtime" placeholder="发票签收日期" clearable style="width: 100%;"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item label="签收备注:">
              <el-input type="textarea" :disabled="formData.supticket_status!=4" v-model="formData.supticket_signedmemo" clearable :rows="3" placeholder="签收时请填写快递单号及签收日期,方便后期查询!"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="进项备注:">
              <el-input type="textarea" v-model="formData.supticket_memo" placeholder="进项发票备注信息"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false" size="medium">取 消</el-button>
      <el-button type="primary" @click="handleSave" size="medium">提交保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
  let Base64 = require('js-base64').Base64;
  import axios from 'axios';
  export default {
    data() {
      return {
        index: -1,
        gwsid: '',
        formData: {
          ordercode: '',
          orderdate: ''
        },
        inputIdValue: '',
        supticket_ids: [],
        inputTicketIdVisible: false,
        supticket_same: '相符',
        dialogVisible: true,
        taxclassifylist: [],
        //文件上传相关变量
        upconfig: {
          //文件上传相关参数
          accept: '.jpg,.jpeg,.png',
          limit: 8,
          headers: {
            token: localStorage.getItem('token') != null ? localStorage.getItem('token') : ''
          },
          imgList: [],
          fileList: [],
          rids: [], //要删除的id
          action: axios.default.baseURL + "/upload/ticketin"
        },
      }
    },

    filters: {
      //保留2位小数点过滤器，不四五入
      number(value, n = 2) {
        //var toFixedNum=parseFloat(value).toFixed(n);
        var toFixedNum = parseFloat(value).toFixed(n);
        var realVal = toFixedNum.substring(0, toFixedNum.toString().length);
        return realVal;
      }
    },
    methods: {
      init: function(index, data) {
        this.index = index;
        this.formData = data;
        this.supticket_same = data.supticket_same == 1 ? '相符' : '不相符';
        this.supticket_ids = data.supticket_ids;
        this.upconfig.imgList = data.supticket_attach;
      },
      format2Number(value, len) {
        var f = parseFloat(value);
        var f = Math.round(value * 100) / 100;
        var s = f.toString();
        var rs = s.indexOf('.');
        if (rs < 0) {
          rs = s.length;
          s += '.';
        }
        while (s.length <= rs + len) {
          s += '0';
        }
        return s;
        return realVal;
      },
      handleSave: function() {
          const params={
              gwsid:this.formData.gwsid,
              status:this.formData.supticket_status,
              msg:this.formData.supticket_verifymsg,
              same:this.supticket_same=='相符'? 1:0,
              amount:this.formData.supticket_amount,
              date:this.formData.supticket_status==4? this.formData.supticket_signedtime:"",
              memo:this.formData.supticket_status==4? this.formData.supticket_signedmemo:"",
              supticket_memo:this.formData.supticket_memo
          }
          this.axios.post("api/admin/jd/order/update_supticket_verify",params).then(res=>{
            if(res.status==200 && res.data.code==0){
               this.$message.success({message:res.data.msg,duration:1500,showClose:true});
               this.dialogVisible=false;
               this.formData.supticket_same=params.supticket_same;
               this.$emit("closeHandler",this.index,params);
            }else{
               this.$message.error({message:res.data.msg,duration:1500,showClose:true});
            }
          })
      },
    }
  }
</script>

<style>
  .el-tag+.el-tag {
    margin-left: 10px;
  }

  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }

  .input-new-tag {
    width: 120px;
    margin-left: 10px;
    vertical-align: bottom;
  }
</style>
